package com.xtravel.common.helper;

import com.xiaomi.mipush.sdk.MiPushClient;
import com.xtravel.application.XtravelApplication;
import org.apache.commons.lang3.StringUtils;

/**
 * @author kuner
 *         <p/>
 *         15-9-17.
 */
public class MiHelper {

    public static final String APP_ID = "2882303761517384588";
    public static final String APP_KEY = "5251738433588";

    /**
     * 绑定用户.
     *
     * @param userName 用户名/手机号.
     */
    public static void setUserAccount(String userName) {
        if (StringUtils.isNotBlank(userName)) {
            MiPushClient.setUserAccount(XtravelApplication.context(), userName, null);
        }
    }

    /**
     * 绑定alias.
     *
     * @param alias Alias.
     */
    public static void setAlias(String... alias) {
        if (alias != null && alias.length > 0) {
            for (String o : alias) {
                MiPushClient.setAlias(XtravelApplication.context(), o, null);
            }
        }
    }

    /**
     * 取消alias绑定.
     *
     * @param alias Alias.
     */
    public static void unsetAlias(String... alias) {
        if (alias != null && alias.length > 0) {
            for (String o : alias) {
                MiPushClient.unsetAlias(XtravelApplication.context(), o, null);
            }
        }
    }

    /**
     * 注册小米推送服务.
     */
    public static void registerPushService() {
        if (XtravelApplication.isFirstInit()) {
            MiPushClient.registerPush(XtravelApplication.context(), APP_ID, APP_KEY);
        }
    }

}
